//
//  YYMemberVC.m
//  drivingSchool
//
//  Created by 子yu 刘 on 2018/9/10.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "YYMemberVC.h"
#import "YYInspectVC.h"
#import "YYSourceVC.h"
#import "YYSeraviceVC.h"
#import "YYPacjageVC.h"
#import "YYMineView.h"
#import "YYWebViewVC.h"

@interface YYMemberVC ()
@property (nonatomic,strong)NSArray * bottmeArr;

@end

@implementation YYMemberVC

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    if (@available(iOS 11.0, *)) {//解决隐藏导航栏scrollView不能到顶的问题
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
//    self.topView.layer.shadowOffset = CGSizeMake(1, 1);
//    self.topView.layer.shadowOpacity = 0.8;
//    self.topView.layer.shadowColor = [UIColor colorWithWhite:0.7 alpha:1].CGColor;
//    self.bottmeView.layer.shadowOffset = CGSizeMake(1, 1);
//    self.bottmeView.layer.shadowOpacity = 0.8;
//    self.bottmeView.layer.shadowColor = [UIColor colorWithWhite:0.7 alpha:1].CGColor;
    [UIView animateWithDuration:2.0 animations:^{
            self.bgShanImg.transform = CGAffineTransformMakeRotation(M_PI);
    }];
    [self reloadData];
    [self getData];
}

- (void)getData{
    [RequestOperationManager PersonalLink_success:^(id result) {
        if (DEF_REQ_SUCCESS) {
            self.bottmeArr = [result[@"data"] copy];
            if (self.bottmeArr.count == 0) {
                self.bottmeView.hidden = YES;
                self.titleView.hidden = YES;
            }else{
                self.bottmeView.hidden = NO;
                self.titleView.hidden = NO;
            }
            [self addbottmeView];
        }
    } failture:^(NSError *error) {
        
    }];
}

- (void)addbottmeView{
    for (UIView * view in self.bottmeView.subviews) {
        [view removeFromSuperview];
    }
    CGFloat width = (DEF_SCREEN_WIDTH()+1)/3;
    CGFloat height = width*207/249;
    self.bottmeHeight.constant = (height)*((self.bottmeArr.count+2)/3);
    for (int i = 0; i<self.bottmeArr.count; i++) {
        YYMineView * view = [[YYMineView alloc] initWithFrame:CGRectMake((i%3)*(width), (i/3)*(height), width, height)];
        [view setDataWithDict:self.bottmeArr[i]];
        MJWeakSelf;
        view.clickdeBlock = ^{
            YYWebViewVC * webView = [[YYWebViewVC alloc] init];
            [webView loadUrl:weakSelf.bottmeArr[i][@"url"]];
            webView.title =weakSelf.bottmeArr[i][@"title"];
            [self.navigationController pushViewController:webView animated:YES];
        };
        [self.bottmeView addSubview:view];
    }
    
}

- (void)reloadData{
    self.lbPhone.text = [UserCenterData sharedInstance].iphone;
    self.lbSource.text = [UserCenterData sharedInstance].integral;
}

- (IBAction)back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


- (IBAction)jianche:(id)sender {
    UITapGestureRecognizer * tap = (UITapGestureRecognizer *)sender;
    if (tap.view.tag ==11) {
        YYInspectVC * inspect = (YYInspectVC *)[CFUtility getVC:@"YYInspectVC" Storyboard:MINE];
        [self.navigationController pushViewController:inspect animated:YES];
    }
    if (tap.view.tag == 12) {
        [RequestOperationManager personalAccident_success:^(id result) {
            if (DEF_REQ_SUCCESS) {
                NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@",result[@"data"][@"iphone"]];
                if (@available(iOS 10.0, *)) {
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone] options:@{} completionHandler:nil];
                } else {
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
                }
            }
        } failture:^(NSError *error) {
            
        }];
        
    }
    if (tap.view.tag == 13) {
        
        YYPacjageVC * package = (YYPacjageVC *)[CFUtility getVC:@"YYPacjageVC" Storyboard:PACKAGE];
        [self.navigationController pushViewController:package animated:YES];
        
    }
    if (tap.view.tag == 14) {
    YYSeraviceVC * seracice = (YYSeraviceVC *)[CFUtility getVC:@"YYSeraviceVC" Storyboard:SERAVICE];
        [self.navigationController pushViewController:seracice animated:YES];
    }
}

- (IBAction)toSource:(id)sender {
    YYSourceVC * source = (YYSourceVC *)[CFUtility getVC:@"YYSourceVC" Storyboard:MINE];
    [self.navigationController pushViewController:source animated:YES];
    
}



@end
